#include "app_mqtt.h"
#include "unistd.h"

#include <string.h>

void mqtt_recv_cb(MQTTClient_message *msg)
{
    log_debug("Received message: %.*s", msg->payloadlen, msg->payload);
}

int main(int argc, char const *argv[])
{

    if (app_mqtt_init() != SUCCESS)
    {
        log_error("MQTT init failed");
    }

    if (app_mqtt_regRecvCb(mqtt_recv_cb) != SUCCESS)
    {
        log_error("MQTT register recv cb failed");
    }

    char *payload = "Hello MQTT";

    if (app_mqtt_publish(payload, strlen(payload)) != SUCCESS)
    {
        log_error("MQTT publish failed");
    }

    sleep(60);

    if (app_mqtt_close() != SUCCESS)
    {
        log_error("MQTT close failed");
    }

    return 0;
}
